package com.weeego.web.base;

import java.util.ArrayList;

public class Page extends Model {

    private static final long serialVersionUID = 1L;
    private static int DEFAULT_PAGE_SIZE = 10;
    private int pageSize = DEFAULT_PAGE_SIZE;
    private Long totalPageCount;
    private int nowpage;
    private Object data;
    private long totalSize;
    private boolean next;
    private boolean previous;

    public boolean isNext() {
        //if nowpage is less than totalpagecount 
        if (getNowpage() < this.totalPageCount) {
            return true;
        } else {
            return false;
        }
    }

    public void setNext(boolean next) {
        this.next = next;
    }

    public boolean isPrevious() {
        //if nowpage Large than 1 and nowpage less than totalpagecounts
        if (getNowpage() > 1) {
            return true;
        } else {
            return false;
        }
    }

    public void setPrevious(boolean previous) {
        this.previous = previous;
    }

    @SuppressWarnings("unchecked")
    public Page() {
        this(0, new Long(0), DEFAULT_PAGE_SIZE, new ArrayList());
    }

    public Page(int nowpage, Long totalCount, int pageSize, Object data) {
        this.pageSize = pageSize;
        this.nowpage = nowpage;
        this.totalSize = totalCount;
        this.data = data;

        int a_totalSize = (int) totalSize;
        int a_totalPageCount = (a_totalSize - 1) / pageSize + 1;
        totalPageCount = new Long(a_totalPageCount);
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Long getTotalPageCount() {
        return totalPageCount;
    }

    public void setTotalPageCount(Long totalPageCount) {
        this.totalPageCount = totalPageCount;
    }

    public int getNowpage() {
        return nowpage;
    }

    public void setNowpage(int nowpage) {
        this.nowpage = nowpage;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }
}
